package com.java1412.controller;

import com.java1412.dao.ParentRepository;
import com.java1412.entity.ParentNode;
import com.java1412.entity.RelationEdge;
import com.java1412.entity.SonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * @author java1412
 * @create 2021-07-05 14:20
 */
@RestController
@RequestMapping("/node")
@Slf4j
public class Neo4jController {

    @Autowired
    private ParentRepository parentRepository;

    @GetMapping(value = "/create")
    public void createNodeRelation() {
        SonNode sonNode1 = new SonNode("儿子小帅");
        SonNode sonNode2 = new SonNode("女儿小美");
        ParentNode parentNode = new ParentNode("爸爸：张三");
        parentNode.addRelation(sonNode1, "儿子");
        parentNode.addRelation(sonNode2, "儿子");
        parentRepository.save(parentNode);
    }

    @GetMapping(value = "/find")
    public void findNodes() {
        List<ParentNode> parentNodes = parentRepository.findAll();
        for (ParentNode parentNode : parentNodes) {
            Set<RelationEdge> relationNodes = parentNode.getSets();
            for (RelationEdge relationNode : relationNodes) {
                System.out.println("id : " + parentNode.getId() + " name : " + parentNode.getName() + " 关系 : " + relationNode.getName());
            }
        }
    }
}
